import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout/index.vue'


Vue.use(VueRouter)

export const routes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path(.*)',
      component: () => import('@/views/redirect')
    }]
  },
  {
    path: '/404',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  {
    path: '/login',
    component: () => import('@/views/login/login.vue')
  },
  {
    path: '/',
    redirect: '/index',
    code: 'indexLayout',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/index.vue')
      }
    ]
  },
]


export const dynamicRoutes = [
    {
        path: '',
        code: 'eventLayout',
        component: Layout,
        meta: {
            title: '事件中心',
            icon: 'el-icon-tickets',
            roles: ['admin']
        },
        children: [
            {
                path: 'eventManage',
                name: 'EventManage',
                component: () => import('@/views/eventManage/index.vue'),
                meta: {
                    title: '事件管理',
                    roles: ['admin']
                }
            },
        ]
    }]
// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
 if (onResolve && onReject) {
 routerPush.call(this, location, onResolve, onReject)
} else {
 routerPush.call(this, location, () => { }, () => { })
}
}


const router = new VueRouter({
  routes
})
export default router
